﻿@using Model.Category;
@using Bll.Category;
@{
    Layout = null;
}

@helper RenderLink(CategoryModel model)
{
    <a href="@(model.LinkURL)" target="@(model.OpenTarget())">
        @if (ValidateHelper.IsPlumpString(model.IconClass))
        {
            <span class="@(model.IconClass)"></span>
        }
        <span>@(model.CategoryName)</span>
    </a>
}

<style type="text/css">
    .dropdown:hover > .dropdown-menu {
        display: block;
    }
</style>

<div id="nav_wrapper">
    <div class="navbar nav_cls z-depth-1" style="margin-bottom: 20px;">

        <div class="container">
            <!-- logo和折叠按钮 -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main_nav">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand logo-img" href="/page/home/" target="_self">
                    @(web_name)
                </a>
            </div>

            <!-- 导航 -->
            <div class="collapse navbar-collapse" id="main_nav">

                @{
                    var list = Com.NewIfNull<List<CategoryModel>>("nav_list");

                    if (ValidateHelper.IsPlumpList(list))
                    {
                        <ul class="nav navbar-nav navbar-left">
                            @foreach (var model in list.Where(x => x.CategoryLevel == CategoryBll.FIRST_LEVEL))
                            {
                                var droplist = list.Where(
                                    x => x.CategoryParent == model.UID
                                    && x.CategoryLevel == model.CategoryLevel + 1).ToList();
                                var li_cls = ValidateHelper.IsPlumpList(droplist) ? "dropdown" : "no_dropdown";

                                <li class="@(li_cls)">
                                    @(RenderLink(model))
                                    @if (ValidateHelper.IsPlumpList(droplist))
                                    {
                                        <ul class="dropdown-menu">
                                            @foreach (var drop in droplist)
                                            {
                                                <li>
                                                    @(RenderLink(drop))
                                                </li>
                                            }
                                        </ul>
                                    }
                                </li>
                            }
                        </ul>
                    }
                }

                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/page/help/" target="_blank" data-toggle="tooltip" data-placement="bottom" title="帮助">
                            <span class="fa fa-life-ring"></span>
                            <span style="text-indent:-999999px;display:inline-block;width:0;">帮助</span>
                        </a>
                    </li>
                    <li>
                        <a href="/user/msg/" class="layer_win" target="_blank" data-toggle="tooltip" data-placement="bottom" title="消息" style="color:red;">
                            <span class="fa fa-bell-o"></span>
                            <span><strong>3</strong></span>
                            <span style="text-indent:-999999px;display:inline-block;width:0;">消息</span>
                        </a>
                        <script type="text/javascript">
                            $(function () {
                                setInterval(function () {
                                    /*
                                    postJson('/user/msgcount/', {}, function (res) {
                                        if (res && res.success) {
                                            if (res.data == '0') {
                                                //
                                            }
                                            else {
                                                //
                                            }
                                        }
                                    });
                                    */
                                }, 1000 * 30);
                            });
                        </script>
                    </li>
                    @if (this.X.User != null)
                    {
                        <li class="dropdown">
                            <a href="/user/me/" rel="nofollow" target="_self">
                                <span class="fa fa-user"></span>
                                <span>@(this.X.User.NickName)</span>
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="/user/userinfo" rel="nofollow" target="_self">
                                        <span>个人设置</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="/account/logout" rel="nofollow" target="_self">
                                        <span>退出</span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    }
                    else
                    {
                        <li>
                            <a href="/account/login" rel="nofollow" target="_self">
                                <span class="fa fa-lock"></span>
                                <span>登陆</span>
                            </a>
                        </li>
                    }

                </ul>

            </div>
        </div>

    </div>
</div>
